package com.example.tumorrecognitionassistant.widget.widget1;

import com.example.tumorrecognitionassistant.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;

/**
 * Widget1Slice used to implement phone call
 */
public class Widget1Slice extends AbilitySlice {
//    @Override
//    public void onStart(Intent intent) {
//        Component component = LayoutScatter.getInstance(this).parse(ResourceTable.Layout_immersive_data_widget1, null, false);
//        super.setUIContent((ComponentContainer) component);
//    }
//
//    @Override
//    public void onActive() {
//        super.onActive();
//    }
//
//    @Override
//    public void onForeground(Intent intent) {
//        super.onForeground(intent);
//    }
    @Override
    public void onStart(Intent intent) {
        super.setUIContent(ResourceTable.Layout_main_ability_slice);
        super.onStart(intent);
        initComponents();
    }

    private void initComponents() {
        Component takePhoto = findComponentById(ResourceTable.Id_take_photo);
        Component videoRecord = findComponentById(ResourceTable.Id_video_record);
        takePhoto.setClickedListener((component) -> startAbility(TakePhotoAbility.class.getName()));
        videoRecord.setClickedListener((component) -> startAbility(VideoRecordAbility.class.getName()));
    }

    private void startAbility(String abilityName) {
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName(getBundleName())
                .withAbilityName(abilityName)
                .build();
        Intent intent = new Intent();
        intent.setOperation(operation);
        startAbility(intent);
    }
}
